using Astronergy.EFCore.GenericRepository;
using Astronergy.Model.Contexts;
using Microsoft.EntityFrameworkCore;
using Microsoft.OpenApi.Models;
using NLog.Extensions.Logging;
using System.Reflection;

IConfiguration configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.Build();

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Logging.AddNLog("Configs/Nlog.config");
builder.Services.AddControllers().AddNewtonsoftJson();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddDbContext<FrameContext>(option => option.UseSqlServer(configuration.GetConnectionString("FrameConnectionString")));
builder.Services.AddGenericRepository<FrameContext>();
builder.Services.AddSwaggerGen(options =>
{
    var xmlPath = Path.Combine(AppContext.BaseDirectory, $"{Assembly.GetExecutingAssembly().GetName().Name}.xml");
    options.SwaggerDoc("v1", new OpenApiInfo { Title = "Astronergy Api", Version = "v1" });
    options.IncludeXmlComments(xmlPath, true);
});

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseAuthorization();

app.MapControllers();

app.Run();